<!DOCTYPE html>
<html>
<head>
    <title>API测试</title>
</head>
<body>
    <h1>API测试页面</h1>
    <button onclick="testRegister()">测试注册</button>
    <button onclick="testLogin()">测试登录</button>
    <div id="result"></div>

    <script>
        async function testRegister() {
            try {
                const response = await fetch('http://localhost:8080/api/auth/register', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({
                        username: 'testuser',
                        password: 'test123',
                        confirmPassword: 'test123',
                        fullName: '测试用户',
                        email: 'test@example.com',
                        role: 'CUSTOMER'
                    })
                });
                
                const data = await response.text();
                document.getElementById('result').innerHTML = 
                    '<h3>注册结果:</h3><pre>' + data + '</pre>';
            } catch (error) {
                document.getElementById('result').innerHTML = 
                    '<h3>注册错误:</h3><pre>' + error.message + '</pre>';
            }
        }

        async function testLogin() {
            try {
                const response = await fetch('http://localhost:8080/api/auth/login', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({
                        username: 'admin',
                        password: 'admin123'
                    })
                });
                
                const data = await response.text();
                document.getElementById('result').innerHTML = 
                    '<h3>登录结果:</h3><pre>' + data + '</pre>';
            } catch (error) {
                document.getElementById('result').innerHTML = 
                    '<h3>登录错误:</h3><pre>' + error.message + '</pre>';
            }
        }
    </script>
</body>
</html>
